/**
 * 案例模块
 */

 define(function (require) {
	var $ = require('jquery');
	// var base = require('base');
	// var com = require('./common');

    if(localStorage.getItem("lang")){
		var Lang = localStorage.getItem("lang")
	}else{
		var Lang = "zh_CN"
	}

	// 中文/英文转换
	if(Lang != "zh_CN"){
		$('#xmanli').html("Project Cases")
		$('#Cases_Introduction').html("Cases Introduction")
		$('#keyword').attr("placeholder", "Enter search keywords")
	}    

    let caseData = {
        nav_id: '',
        keyword:''
    }

    // 获取案例列表
    getCase = function(){
        // 获取案例列表
        $.ajax(seajs.ajaxroot + "getCases",{
            type:'post',
            data:caseData,
            headers:{
                'locale-language':Lang
            },
            success:function(res){
                let screen_width = $(window).width()
                let margin_width = (screen_width*0.833*0.04)/6 -1
 
                let htmlData = '';

                if(Lang == "zh_CN"){
                    res.data.forEach((item, index)=>{
                        htmlData += '<div class="anli" style="margin-left:'+margin_width+'px;margin-right:'+margin_width+'px"><div class="anli_img"><img src="'+item.img+'" /></div>';
                        htmlData += '<div class="anli_content">';
                        htmlData += '<p>应用领域：<span>'+item.application_area+'</span></p>';
                        htmlData += '<p>安装地点:<span>'+item.address+'</span></p>';
                        htmlData += '<p>装机容量:<span>'+item.volume+'</span></p>';
                        htmlData += '<p>运营时间:<span>'+item.run_time+'</span></p>';
                        htmlData += '<p>系统特点:<span>'+item.feature+'</span></p>';                
                        htmlData += '</div></div>';
                    })
                }else{
                    res.data.forEach((item, index)=>{
                        htmlData += '<div class="anli" style="margin-left:'+margin_width+'px;margin-right:'+margin_width+'px"><div class="anli_img"><img src="'+item.img+'" /></div>';
                        htmlData += '<div class="anli_content">';
                        htmlData += '<p>Application Area：<span>'+item.application_area+'</span></p>';
                        htmlData += '<p>Address:<span>'+item.address+'</span></p>';
                        htmlData += '<p>Volume:<span>'+item.volume+'</span></p>';
                        htmlData += '<p>Run time:<span>'+item.run_time+'</span></p>';
                        htmlData += '<p>Features:<span>'+item.feature+'</span></p>';                
                        htmlData += '</div></div>';
                    })                    
                }



                $('#anli_list').html(htmlData);
            }
        })
        
    }


	// 获取案例行业分类
	$.ajax(seajs.ajaxroot + "getCaseCate",{
		type:'post',
		headers:{
			'locale-language':Lang
		},
		success:function(res){
            let selectLIst
            if(Lang != "zh_CN"){
                selectLIst = '<option disabled selected value>- All Industry Classifications</option>';
            }else{
                selectLIst = '<option disabled selected value>- 全部行业分类</option>';
            }
            
            res.data.forEach(item=>{
                selectLIst += '<option value ="'+item.id+'">'+item.title+'</option>';
            })
            $('#industry_type').html(selectLIst)
            getCase();
        }
    })


    tusubmit = function(){
        caseData.nav_id = $('#industry_type').val();
        caseData.keyword = $('#keyword').val();
        getCase()
    }


 })
